﻿using System;
using System.Collections.Generic;
using Core.Interfaces;
using Core.Model;

namespace Core.Services
{
    public class CatalogService : ICatalogService
    {
        private readonly ICatalogRepository _catalogRepository;
       

        public CatalogService(ICatalogRepository catalogRepository)
        {
            if (catalogRepository == null) throw new ArgumentNullException("catalogRepository");
            _catalogRepository = catalogRepository;
        }

        public Category GetCategory(string categoryId)
        {
            if (categoryId == null) throw new ArgumentNullException("categoryId");

            return _catalogRepository.GetCategory(categoryId);
        }

        public List<Product> GetProductsByCategory(string category)
        {
            if (string.IsNullOrEmpty(category))
                return null;
         
            return _catalogRepository.GetProductsByCategory(category);
        }



        public Product GetProduct(string productId)
        {
            if (productId == null) throw new ArgumentNullException("productId");
            return _catalogRepository.GetProduct(productId);
        }

        public List<Item> GetItemsPerProduct(string productId)
        {
            if (productId == null) throw new ArgumentNullException("productId");
            return _catalogRepository.GetItemsPerProduct(productId);
        }


        public Item GetItemDetails(string itemId)
        {
            if (itemId == null) throw new ArgumentNullException("itemId");
            return _catalogRepository.GetItem(itemId);
        }
    }
}
